<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="engineer.clientapp.beans.User" %>
<%@ page import="engineer.clientapp.tools.Connector" %>

<%
User user=(User)session.getAttribute("user");

%>
<%if (session.getAttribute("user") == null) {%>
<h1>Brak dostępu do tej strony!</h1>
<%}else{ 
%>
<h1>Zarządzanie Automatami</h1>
<div id="gallery_container">
<h3>Dodaj Automat</h3>

<html:form action='addMachine' enctype="multipart/form-data">
	<table>
		<tr>
		<td><label class="panel" for="login"><bean:message key="label.machine.machineName" /> </label></td> <td><input id="machineName" name="machineName" type="text"/></td>
		</tr>
		
		
		<tr>
		<td><label class="panel" for="login"><bean:message key="label.machine.address" /> </label></td> <td><input id="address" name="address" type="text"/></td> 
		</tr>
		
		<tr>
		<td><label class="panel" for="login"><bean:message key="label.machine.maxAmount" /> </label></td> <td><input id="maxAmount" name="maxAmount" type="text"/></td> 
		</tr>
		
		<tr>
		<td><label class="panel" for="login"><bean:message key="label.machine.image" /> </label></td> <td><html:file property="file" size="50" /></td> 
		</tr>

		</table> 
		
		<br>
		<center><input type="submit" class="styled-button-2" value="Dodaj"/></center>
		<p class="forgot-password">
		
			<font color="red"><html:errors property="error" /></font></p>
</html:form>
<br><br>

<h3>Usuń Automat</h3>
<%
Connection connection = new Connector().getConnection();
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery("SELECT id, name FROM automats.machines");
int numberOfRows = Connector.getRowCount(result);
%>
<html:form action="deleteMachine"> 
<table>
<tr>
<td>
<div class="styled-select">
				<select name="id" id="id">
				<option value="0">Wybierz maszynę do usunięcia... </option>
				<%
				
				while(result.next()){%>
				<option value="<%=result.getInt("id") %>"><%=result.getString("name")%></option>
				
			<% }%>
			</select>
			</div></td>
			<td>
				<input type="submit" id="submit" class="styled-button-3" value="Usuń" /></td>
				</tr>
</table>
<p class="forgot-password">
		
			<font color="red"><html:errors property="info" /></font></p>

	</html:form>


</div>
</div>
<%}%>